import axios from 'axios';

const baseUrl = '/sc/menu/';
const apis = {
  menuIds:`/sc/role/menuIds`,
  assignMenus:`/sc/role/assignMenus`,
  getMenuList: `${baseUrl}getMenus`,
  getMenuTrees: `${baseUrl}menuTrees`,
  detail: `${baseUrl}detail`,
  addForm: `${baseUrl}add`,
  editForm: `${baseUrl}edit`,
  deleteRow:`${baseUrl}delete`,
  menuListTree:`${baseUrl}menuTreeForAssign`,
  downMenuTs:`${baseUrl}downMenuTs`

};


export interface RegisterData {
  account: string;
  password: string;
  name: string;
  email: string;
}

export interface menu {
  id: string;
  parentId: string;
  weight: number | null;
  name: string | null;
  menuName: string;
  menuPath: string;
  menuType: number;
  routeName: string;
  routePath: string;
  perms: string;
  enable: boolean;
  component: string;
}

export interface MenuData {
  menus: menu[];
}

export  function getMenuList() {
   return  axios.get<MenuData>(apis.getMenuList);
}

export function menuTrees() {
  return axios.get<menu[]>(apis.getMenuTrees);
}

export function detail(rowId:string) {
  return axios.get<any>(`${apis.detail}?id=${rowId}`);
}

export function addForm(param:any) {
  return axios.post<string>(apis.addForm,param);
}

export function editForm(param:any) {
  return  axios.post<string>(apis.editForm,param);
}

export function removeRow(rowId: string) {
  return axios.delete<string>(`${apis.deleteRow}?id=${rowId}`);
}

export function menuIds(rowId:string) {
  return axios.get<any>(`${apis.menuIds}?id=${rowId}`);
}

export function menuListTree() {
  return axios.get<any>(`${apis.menuListTree}`);
}

export function assignRoleMenu(data:any) {
  return axios.post<any>(`${apis.assignMenus}`,data);
}

export function downTs() {
  return axios.post<any>(apis.downMenuTs,{},{
    responseType:'blob'
  });
}


